odoo.define('activity_popover/static/src/components/activity_popover/activity_popover.js', function (require) {
'use strict';


const { Component } = owl;
const { DropPrevious } = require("web.concurrency");

class ActivityPopover extends Component {

    /**
     * @param {...any} args
     */
    constructor(...args) {
        super(...args);
        this.dp = new DropPrevious();
        this.records = null

    }

    async willStart() {
        await this._fetchRecords({
            domain: [],
            context: {
              "lang": "zh_CN",
              "tz": "Asia/Shanghai",
            }
        });
    }

    async _fetchRecords(searchQuery) {
        const { domain, context} = searchQuery;
        const { length, records } = await this.dp.add(
            this.env.services.rpc({
                route: "/web/dataset/search_read",
                model: "mail.activity.type",
                fields: ["name"],
                domain,
                context
            })
        );
        this.records = records;
    }

    mounted() {
        this._update();
    }

    patched() {
        this._update();
    }

    //--------------------------------------------------------------------------
    // Private
    //--------------------------------------------------------------------------

    /**
     * @private
     */
    _update() {
        this.trigger('o-popover-compute');
    }

    //--------------------------------------------------------------------------
    // Public
    //--------------------------------------------------------------------------

    close() {
        this.trigger('o-popover-close');
    }

    /**
     * Returns whether the given node is self or a children of self.
     *
     * @param {Node} node
     * @returns {boolean}
     */
    contains(node) {
        if (!this.el) {
            return false;
        }
        return this.el.contains(node);
    }

    //--------------------------------------------------------------------------
    // Handlers
    //--------------------------------------------------------------------------

    /**
     * @private
     * @param {MouseEvent} ev
     */
    _onClickActivity(ev) {
        this.close();
        this.trigger('o-activity-selection', {
            name: ev.currentTarget.dataset.name,
        });
    }

}

Object.assign(ActivityPopover, {
    props: {},
    template: 'activity_popover.ActivityPopover',
});

return ActivityPopover;

});
